// hyb_yl/pharmacy/pages/equipment/equipment.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    page:0,
    
  },
  add:function(){
    wx.navigateTo({
      url: '/hyb_yl/pharmacy/pages/scan_add/scan_add?j_id='+this.data.j_id,
    })
  },
  user_choose:function(e){
    var id = e.currentTarget.dataset.id;
    var j_id = e.currentTarget.dataset.j_id;
    var type = e.currentTarget.dataset.type;
    var sn = e.currentTarget.dataset.sn;
    app.util.request({
      'url':"entry/wxapp/index.changebundling",
      data:{
        sn:sn,
        openid:wx.getStorageSync('openid'),
        j_id:j_id,
        type:type,
      },
      success:function(res){
        that.setData({
          list:[],
          page:0
        })
        that.getList();
      }
    })
  },
  // 解绑
  unbundling:function(e){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/index.unbundling",
      data:{
        id:e.currentTarget.dataset.id,
        openid:wx.getStorageSync('openid'),
      },
      success:function(res){
        wx.showModal({
          title: '提示',
          content:res.data.message,
          showCancel:false,
          success:function(con){
            that.setData({
              page:0,
              list:[]
            })
            that.getList();
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      names:options.names,
      j_id:options.j_id,

    })
    wx.setNavigationBarTitle({
      title: '患者设备',
    })
    that.getList();
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getList();
  },
  getList:function(){
    var that = this;
    app.util.request({
      'url':"enrty/wxapp/index.user_equipment",
      data:{
        openid:wx.getStorageSync('openid'),
        page:that.data.page
      },
      success:function(res){
        var page = that.data.page;
        page = page + 1;
        that.setData({
          list:that.data.list.concat(res.data),
          page:page
        })
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})